<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getMost(str) {

            // 步骤1
            var result = {};
            for (let i in str) {
                if (str[i] in result) {
                    // 步骤2
                    result[str[i]]++;
                } else {
                    // 步骤3
                    var object = {};
                    object[str[i]] = 1;
                    result = Object.assign(result, object);
                }
            }
            return result;
        }

        var result = getMost("xyzzyxyz");
        console.log(result); 
    </script>
</body>

</html>